//导入请求工具类
import request from '@/utils/request.js'

//首页带查询的商品列表（商品分类以及商品名称）
export const goodsListService = (params)=>{
    return  request.get('/goods/findByNameGcId',{params:params})
}

//获取商品分类列表
export const categoryListService=()=>{
    return request.get('/goodscategory')
}
//添加分类
export const categoryAddService=(categoryData)=>{
    return request.post('/goodscategory',categoryData)
}
//修改分类
export const categoryUpdateService=(categoryData)=>{
    return request.put('/goodscategory',categoryData)
}

//获取商品所有信息（管理员审核商品页面展示）
export const goodsInfoTotalService = ()=>{
    return request.get('/goods/totalGoods');
}
//查询要审核的商品（管理员审核页面）
export const goodsSearchService = (params)=>{
    return  request.get('/goods/searchGoods',{params:params})
}
//审核通过商品
export const goodsApprovedService = (goodsId) => {
    return request.put(`/goods/approved?goodsId=${goodsId}`);
};

//审核  未通过商品
export const goodsNotApprovedService = (goodsId,reason) => {
    // 对 reason 参数进行编码，确保它不会破坏 URL 结构
    const encodedReason = encodeURIComponent(reason);
    const goodsIdStr = String(goodsId);
    // 使用 & 来分隔参数
    return request.put(`/goods/notApproved?goodsId=${goodsIdStr}&reason=${encodedReason}`) ;
};
//供应商端获取商品列表
export const goodListService=(params)=>{
    return request.get('/goods/listSgoods',{params:params})
}

//添加商品
export const goodsAddService=(goodData)=>{
    return request.post('/goods', JSON.stringify(goodData), {
        headers: {
            'Content-Type': 'application/json'
        }
    });
}
//修改商品
export const goodUpdateService = (goodData)=>{
    return  request.put('/goods',goodData)
}
//删除商品
export const goodDeleteService = (g_id)=>{
    return request.delete('/goods?gid='+g_id)
}
//用于数据中心-查询供应商id的商品总数
export const SgoodCountService=()=>{
    return request.get('/goods/SgoodsCount')
}
//用于数据中心-查询供应商id的最受欢迎商品
export const SbestGoodService=()=>{
    return request.get('/goods/SbestGood')
}
//用于数据中心-查询供应商id的总销售额
export const SsoldMoneyService=()=>{
    return request.get('/goods/SsoldMoney')
}
//用于数据中心-查询供应商id的商品销售量列表
export const SsellGoodCountService=()=>{
    return request.get('/goods/SsellGoodCount')
}
//用于数据中心-查询供应商id的商品销售额""列表
export const SsellGoodMoneyService=()=>{
    return request.get('/goods/SsellGoodMoney')
}